package com.lr.chat;

import java.io.BufferedInputStream;
import java.io.BufferedReader;
import java.io.DataInputStream;
import java.io.DataOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.net.Socket;
import java.net.UnknownHostException;

public class ClientOut {

	public static void main(String[] args) throws UnknownHostException, IOException {
		//1.创建客户端,必须指定服务器地址以及端口，此时就已经在连接
		Socket client = new Socket("localhost",8888);
		//输出流
		DataOutputStream dos = new DataOutputStream(client.getOutputStream());
	    BufferedReader console = new BufferedReader(new InputStreamReader(System.in));
	  //输入流
	    DataInputStream dis = new DataInputStream(client.getInputStream());
		while(true){
	        String msg = console.readLine();
	        dos.writeUTF(msg);
	        dos.flush();
	       
	        String data = dis.readUTF();
	        System.out.println(data);
		}
		//发送数据，接受数据是顺序执行的，需要接入多线程
	}

}
